import request from '@/utils/axios/instance';
import type { BaseResponse, Menu } from '../types';

export async function getMenuList() {
  return request<BaseResponse<Menu[]>>({
    method: 'get',
    url: '/system/menu/list',
  });
}

// 查询菜单详细
export function getMenuById(menuId: string) {
  return request({
    url: `/system/menu/${menuId}`,
    method: 'get',
  });
}

// 查询菜单下拉树结构
export function treeSelect() {
  return request({
    url: '/system/menu/treeselect',
    method: 'get',
  });
}

// 根据角色ID查询菜单下拉树结构
export function menuTreeByRoleId(roleId: string) {
  return request({
    url: `/system/menu/roleMenuTreeselect/${roleId}`,
    method: 'get',
  });
}

// 新增菜单
export function addMenu(data: any) {
  return request({
    url: '/system/menu',
    method: 'post',
    data,
  });
}

// 修改菜单
export function updateMenu(data: any) {
  return request({
    url: '/system/menu',
    method: 'put',
    data,
  });
}

// 删除菜单
export function delMenu(menuId: string) {
  return request({
    url: `/system/menu/${menuId}`,
    method: 'delete',
  });
}
